/**
 * Created by pjn on 2017/5/18.
 */
var startRoad4S = "";
var endRoad4S = "";
var roadName4S = "";
var signMainOrgId = 0;
var signOrgId = 0;
var userMobile = "";
//故障类型
var faultType = [{"value": "0", "name": "正常"}, {"value": "1", "name": "膜脱落"}, {"value": "2", "name": "膜淡化"},
    {"value": "3", "name": "逆反射系数不达标"}, {"value": "4", "name": "卷边"}, {"value": "5", "name": "转向"},
    {"value": "6", "name": "非国际"}, {"value": "7", "name": "抱箍缺少"}, {"value": "8", "name": "净空高不达标"},
    {"value": "9", "name": "设置不合理"}, {"value": "10", "name": "缺失"}, {"value": "11", "name": "建议增设"},
    {"value": "12", "name": "与交通组织矛盾"}, {"value": "13", "name": "内容有误"}, {"value": "14", "name": "标牌与标杆不配套"},
    {"value": "15", "name": "非公指示牌"}];

var acReport = 0;
var acAudit = 0;
var acAdmin = 0;
var isAdd = false;

var midHeight;
var mData;
var pointCollection;
var map;
$.setDefaultNum = function () {
    var windowHeight = $(window).height();
    var headerHeight = $("headArea").height() + 100;
    var footerHieght = 100;
    midHeight = windowHeight - headerHeight - footerHieght;
};

$.getActorId = function (data) {
    var actorId = 0;
    if (data.indexOf("6") >= 0) {
        actorId = 6;
        acReport = 1;
    }
    if (data.indexOf("3") >= 0) {
        actorId = 3;
        acAudit = 1;
    }
    if (data.indexOf("1") >= 0) {
        actorId = 1;
        acAdmin = 1;
    }
    return actorId;
};
var gActorId = $.getActorId(gUserLoginResult.userActors);

$(function () {
    gMainDT = $("#mainDataTables").DataTable({
        ajax: {
            url: "../rds_fault/getFault4DT",
            type: "POST",
            data: function (d) {
                d.search = $('#mainDataTables').DataTable().search(this.value);
                d.actorId = gActorId;
                d.gActorId = 3;
                d.orgId = gUserLoginResult.orgId;
                d.userId = gUserLoginResult.userId;
            }
        },
        columns: [{
            data: "signFaultId",
            render: function (data, type, row, meta) {
                var checkId = "checkbox" + (parseInt(meta.row) + 1);
                return "<input type='checkbox' data-status='" + row.companyCheck + "' value='" + data + "' id='" + checkId + "'>";
            }
        }, {
            data: "signFaultId",
            targets: 0
        }, {
            data: "roadSignPic",
            render: function (data, type, row) {
                return "<img src='" + data + "' style='width:50px;height:40px;cursor: pointer' " +
                    "onclick='$.showPicModal(\"" + data + "\")'> ";
            }
        }, {
            data: "signFaultPeopleName"
        }, {
            data: "signFaultTime",
            render: function (data, type, row, meta) {
                return data.substring(0, 10);
            }
        }, {
            data: "orgName"
        }, {
            data: "companyUserName",
            render: function (data, type, row) {
                if (data == "" || data == null) {
                    return "暂未审核"
                } else {
                    return data
                }
            }
        }, {
            data: "roadSignId",
            render: function (data, type, row) {
                var allData = JSON.stringify(row).replace(/\'/g, "&apos;");
                return "<button class='btn btn-primary btn-xs btn-flat' onclick='$.signDetails (" + allData + ")' title='标牌详情'>点击查看</button>";
            }
        }, {
            data: "signFaultId",
            render: function (data, type, row) {
                var allData = JSON.stringify(row).replace(/\'/g, "&apos;");
                return "<button class='btn btn-primary btn-xs btn-flat' onclick='$.faultDetails (" + allData + ")' title='故障详情'>点击查看</button>";
            }
        }, {
            data: "signFaultId",
            render: function (data, type, row) {
                var allData = JSON.stringify(row).replace(/\'/g, "&apos;");
                // 左侧工具栏按钮的权限
                // var buttonInsert = "<button class='btn btn-info btn-xs btn-flat' onclick='$.addFaultReport()' title='添加'><i class='fa fa-plus-square'></i></button>";
                var buttonAudit = "", buttonUpdate = "", buttonOperation = "";
                if (acAudit == 1 || acAdmin == 1 || acReport == 1) {
                    if (row.companyCheck == 0 && (acAudit == 1 || acAdmin == 1))
                        buttonAudit = "<button  class='btn btn-primary btn-xs btn-flat'  onclick='$.showCheckModal(" + allData + ",3)'><span class='glyphicon glyphicon-check' aria-hidden='true' ></span>上报</button>";
                    if (row.companyCheck == -1)
                        buttonAudit = "<button onclick='$.faultInfoDetails (" + allData + ")' class='btn btn-danger btn-xs btn-flat'>未上报</button>";
                    if (row.companyCheck == 1)
                        buttonAudit = "<button onclick='$.faultInfoDetails (" + allData + ")' class='btn btn-success btn-xs btn-flat'>已上报</button>";
                    if (row.companyCheck == 2)
                        buttonAudit = "<button onclick='$.faultInfoDetails (" + allData + ")' class='btn btn-warning btn-xs btn-flat'>已通过</button>";
                    buttonOperation += buttonAudit;
                }
                if (row.companyCheck != 0)
                    buttonUpdate = "<button class='btn btn-primary btn-xs btn-flat' disabled='disabled' title='编辑'><i class='fa fa-edit'></i></button>";
                else
                    buttonUpdate = "<button class='btn btn-primary btn-xs btn-flat' onclick='$.updateFaultReport(" + allData + ")' title='编辑'><i class='fa fa-edit'></i></button>";
                if (acReport == 1 || acAdmin == 1)
                    buttonOperation += "&nbsp&nbsp&nbsp&nbsp" + buttonUpdate;
                return buttonOperation;
            }
        }],
        dom: "<'row'<'col-md-4'l><'#mainToolbar.col-md-8'>r>t<'row'<'col-md-6'i><'#setZ-index.col-md-6'p>>",
        initComplete: function () {
            // 下拉工具栏按钮的权限
            $("#mainToolbar").empty();
            var strToolBar = "<div class='btn-group'><button type='button' class='btn btn-primary btn-sm btn-flat'><i class='fa fa-cog'></i> 操作</button>";
            strToolBar += "<button type='button' class='btn btn-primary btn-sm btn-flat dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>";
            strToolBar += "<span class='caret'></span><span class='sr-only'>切换下拉</span></button><ul class='dropdown-menu'>";
            strToolBar += "<li><button href='#' class='btn btn-primary btn-sm btn-flat btn-block' onclick='gMainDT.ajax.reload(null, false);'><i class='fa fa-reFaultReportesh'></i> 刷新</button></li>";
            var buttonInsert = "<button style='margin-right: 3px;' type='button' class='btn btn-primary btn-sm btn-flat' onclick='$.addFaultReport()'><i class='fa fa-plus-square'></i> 故障申报</button>";
            // 下拉工具栏不处理更新事件，但今后可能需要审核等功能，替换该位置即可
            //var buttonUpdate = "<li><button href='#' class='btn btn-warning btn-sm btn-flat btn-block' onclick='$.updateFaultReport()'><i class='fa fa-edit'></i> 编辑</button></li>";
            var buttonDelete = "<li><button href='#' class='btn btn-primary btn-sm btn-flat btn-block' onclick='$.deleteFaultReport(0)'><i class='fa fa-minus-square'></i> 删除</button></li>";
            gInsert == 0 ? strToolBar : strToolBar = buttonInsert + strToolBar;
            if (acReport == 1 || acAdmin == 1) {
                strToolBar += buttonDelete;
            }
            strToolBar += "</ul></div> <div style='z-index: 0' class='input-group input-group-sm'><input type='text' class='form-control' name='searchText' placeholder='路'>";
            strToolBar += "<span class='input-group-btn'><button class='btn btn-primary btn-flat' type='button' onclick='$(this).searchDT()'><i class='fa fa-search'></i></button></span></div></div>";
            strToolBar = "<div class='pull-right'>" + strToolBar;
            $("#mainToolbar").append(strToolBar);
        },
        processing: true,
        serverSide: true,
        ordering: false,
        select: false,
        autoFill: true,
        displayLength: 20,
        lengthMenu: [[5, 10, 15, 20, 50, 100, 150, -1], [5, 10, 15, 20, 50, 100, 150, "All"]],
        language: {
            url: "zh_cn.json"
        },
        fnDrawCallback: function () {// 序号自增回调函数
            var api = this.api();
            var startIndex = api.context[0]._iDisplayStart;
            api.column(1).nodes().each(function (cell, i) {
                cell.innerHTML = startIndex + i + 1;
            });
        }
    });

    //故障类型初始化(上报时)
    var faultTypeInit = "";
    for (var i = 0; i < faultType.length; i++) {
        faultTypeInit += "<option value='" + faultType[i].value + "'>" + faultType[i].name + "</option>";
    }
    $("#addfault_signFaultType").append(faultTypeInit);


    //$.setDefaultNum();

});


// 搜索框查询操作
$.fn.searchDT = function () {
    // 注意gSelect查询权限的处理，由该表是否存在添加人或者审核人决定
    var searchContext = $("input[name='searchText']").val();
    gMainDT.search(searchContext).draw();
};

// DT头部的复选按钮全选操作
$.checkChange = function () {
    var isChecked = $("#batch_check").prop('checked');
    $("input[type='checkbox']").prop("checked", isChecked);
};
//获取用户电话
$.ajax({
    url: "../rds_user/getUserById",
    type: "POST",
    async: false,
    data: {
        userId: gUserLoginResult.userId
    },
    success: function (msg) {
        if (msg != null && typeof(msg) != "undefined") {
            if (msg.isSuccess == true) {
                userMobile = msg.jsonData.userMobile;
            } else {
                $.alert("获取数据失败", 2);
            }
        }
    }
});
//datatable 图片放大
$.showPicModal = function (jsonData) {
    $("#showPicture").attr("src", jsonData);
    $("#showPicLabel").text("图片");
    $("#showPicModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

//故障状态
$.faultInfoDetails = function (data) {
    var status = -1;
    $(".ystep2").empty();
    $(".ystep2").loadStep({
        size: "large",
        color: "green",
        steps: [{
            title: "故障申报"
        }, {
            title: "内部审核"
        }, {
            title: "上报监管单位"
        }, {
            title: "监管单位审核"
        }, {
            title: "故障处理"
        }, {
            title: "故障完成"
        }]
    });
    $.ajax({
        url: "../rds_fault/getSignFaultStatus",
        type: 'post',
        async: false,
        data: {
            userDevice: 'web',
            roadSignId: data.roadSignId,
            signFaultId: data.signFaultId
        },
        dataType: 'json',
        success: function (msg) {
            console.log(msg)
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    status = msg.jsonData;
                } else
                    $.alert("系统错误！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
    $("#operationRecord").html("<tr>\n" +
        "                            <th>环节名称</th>\n" +
        "                            <th>到达时间</th>\n" +
        "                            <th>处理时间</th>\n" +
        "                            <th>处理人</th>\n" +
        "                            <th>操作类型</th>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>故障申报</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>内部审核</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>上报监管单位</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>监管单位审核</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>故障处理</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>");

    $.ystepTest(status);
    $("#modal-signFaultStatus").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
};
$.ystepTest = function (data) {
    switch (data) {
        case 0://待内部审核
            $(".ystep2").setStep(1);
            break;
        case -1://内部拒绝
            $(".ystep2").setStep(1, 1);
            break;
        case 2://待主管审核
            $(".ystep2").setStep(3);
            break;
        case -2://主管拒绝
            $(".ystep2").setStep(4, 4);
            break;
        case 7://待维修
            $(".ystep2").setStep(4);
            break;
        case 8://维修中
            $(".ystep2").setStep(5);
            break;
        case 3://维修完成
            $(".ystep2").setStep(6);
            break;
        case 9:
            $(".ystep2").setStep(4, [3, 4]);
            break;
        case 10:
            $(".ystep2").setStep(5, [3, 4]);
            break;
        case 11:
            $(".ystep2").setStep(6, [3, 4]);
            break;
        default:
            $(".ystep2").setStep(0);
            break;
    }
}

//故障详情
$.faultDetails = function (data) {
    isAdd = false;
    $("#addfault_signFaultPeopleName").text(data.signFaultPeopleName);
    $("#addfault_signFaultPeopleMobile").text(data.signFaultPeopleMobile);
    $("#addfault_roadName").text(data.roadName);
    $("#addfault_address").text(data.province + "" + data.city + "" + data.area + " " + data.roadName + " " + data.startRoad + "(起)--" + data.endRoad + "(止)");
    $("#addfault_signFaultPic").attr("src", data.signFaultPic);
    $("#addfault_repairAmount").val(data.repairAmount);
    $("#addfault_signFaultType").val(data.signFaultType);
    $("#addfault_signFaultLevel").val(data.signFaultLevel);
    $("#addfault_signFaultReason").val(data.signFaultReason);

    $("#addfault_repairAmount").attr("disabled", true);
    $("#addfault_signFaultType").attr("disabled", true);
    $("#addfault_signFaultLevel").attr("disabled", true);
    $("#addfault_signFaultReason").attr("disabled", true);
    $("#addfault_signBtn").hide();
    $("#addfault_signFaultPic").attr("onclick", "");
    $("#addfault_signMapBtn").hide();
    $("#signbtn").hide();

    $("#addfaultModalLabel").text("故障详情");
    $("#addfaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

//编辑故障上报
$.updateFaultReport = function (data) {
    $("#addfault_signFaultId").val(data.signFaultId);

    $("#addfault_signFaultPeopleName").text(data.signFaultPeopleName);
    $("#addfault_signFaultPeopleMobile").text(data.signFaultPeopleMobile);
    $("#addfault_roadName").text(data.roadName);
    $("#addfault_address").text(data.province + "" + data.city + "" + data.area + " " + data.roadName + " " + data.startRoad + "(起)--" + data.endRoad + "(止)");
    $("#addfault_signFaultPic").attr("src", data.signFaultPic);
    $("#addfault_repairAmount").val(data.repairAmount);
    $("#addfault_signFaultType").val(data.signFaultType);
    $("#addfault_signFaultLevel").val(data.signFaultLevel);
    $("#addfault_signFaultReason").val(data.signFaultReason);

    $("#reportBtn").hide();
    $("#updateBtn").show();
    $("#addfault_signBtn").hide();
    $("#addfault_signMapBtn").hide();

    $("#addfaultModalLabel").text("故障编辑");
    $("#addfaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};
//保存编辑
$.updateFault = function () {
    var repairAmount = $("#addfault_repairAmount").val();
    if (repairAmount == "") {
        repairAmount = 0.00;
    }
    if ($("#addfault_address").text() == "" && $("#addfault_roadName").text() == "") {
        $.alert("请选择标牌", 2);
    } else if ($("#addfault_signFaultReason").val() == "") {
        $.alert("请填写故障原因", 2);
    } else {
        $.ajax({
            url: "../rds_fault/updateSignFaultById",
            type: 'post',
            data: {
                signFaultId: $("#addfault_signFaultId").val(),
                signFaultLevel: $("#addfault_signFaultLevel").val(),
                signFaultType: $("#addfault_signFaultType").val(),
                signFaultPic: $("#addfault_signFaultPic").attr("src"),
                signFaultReason: $("#addfault_signFaultReason").val(),
                repairAmount: repairAmount
            },
            dataType: 'json',
            success: function (msg) {
                if (msg.isSuccess == true) {
                    $.alert("保存成功", 1);
                    gMainDT.ajax.reload(null, false);
                    $("#addfaultModal").modal("hide");

                    $("#addfault_signFaultLevel").val(1);
                    $("#addfault_signFaultType").val(0);
                    $("#addfault_signFaultPic").attr("src", "../images/default_photo.png");
                    $("#addfault_roadName").html("");
                    $("#addfault_address").html("");
                    $("#addfault_repairAmount").val("");
                    $("#addfault_signFaultReason").val("");

                    $("#addfault_roadSignId").val("");
                    $("#addfault_orgId").val("");
                    $("#addfault_mainOrgId").val("");
                    $("#addfault_signFaultId").val("");

                    $("#addfault_signBtn").show();
                    $("#reportBtn").show();
                    $("#updateBtn").hide();
                } else {
                    $.alert("数据操作失败2", 2);
                }
            },
            error: function (msg) {
                $.alert('系统错误，请联系管理员', 2);
            }
        });
    }
};
//添加故障
$.addFaultReport = function () {
    isAdd = true;
    $("#addfault_signFaultPeopleName").text(gUserLoginResult.userName);
    $("#addfault_signFaultPeopleMobile").text(userMobile);

    $("#addfaultModalLabel").text("上报故障");
    $("#reportBtn").attr("disabled", false);
    $("#addfaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};
//显示标杆modal
$.roadPoleDTModal = function () {
    //故障申报
    var actorId;
    if (gUserLoginResult.userActors.indexOf("6") > 0)
        actorId = 6;
    if (gUserLoginResult.userActors.indexOf("1") > 0)
        actorId = 1;
    startRoad4S = "";
    endRoad4S = "";
    roadName4S = "";
    gReportMainDT = $("#roadPoleDTDataTables").DataTable({
        ajax: {
            url: "../rds_roadSignManageController/getRoadPole4ReportDT",
            type: "POST",
            data: function (d) {
                d.search = "";
                d.orgId = gUserLoginResult.orgId;
                d.actorIds = gUserLoginResult.userActors;
                d.startRoad = startRoad4S;
                d.endRoad = endRoad4S;
                d.roadName = roadName4S;
            }
        },
        columns: [{
            data: "roadPoleId",
            targets: 0
        }, {
            data: "roadPolePic",
            render: function (data, type, row) {
                return "<img src='" + data + "' style='width:50px;height:40px;cursor: pointer' " +
                    "onclick='$.showPicModal(\"" + data + "\")'> ";
            }
        }, {
            data: "roadPoleId",
            render: function (data, type, row) {
                var str = "<button id='showMap' onclick='$.showMap(" + row.longitude + "," + row.latitude + "," + data + ")' class='btn  btn-primary  btn-xs btn-flat' title='地图位置'><i class='glyphicon glyphicon-map-marker'></i></button> "
                str += row.province + " " + row.city + " " + row.area;
                return str;
            }
        }, {
            data: "roadName"
        }, {
            data: "roadPoleBridge",
            render: function (data, type, row) {
                var roadPoleBridge = "否";
                if (data == 0)
                    roadPoleBridge = "是";
                return roadPoleBridge;
            }
        }, {
            data: "roadPoleSecurity",
            render: function (data, type, row) {
                var roadPoleSecurity = "安全";
                if (row.roadPoleSecurity != 0) {
                    roadPoleSecurity = "不安全";
                }
                return roadPoleSecurity;
            }
        }, {
            data: "orgName"
        }, {
            data: "userName"
        }, {
            data: "roadPoleCreateTime",
            render: function (data, type, row) {
                return data.substring(0, 10);
            }
        }, {
            data: "roadPoleId",
            render: function (data, type, row) {
                return "<button class='btn btn-primary btn-xs btn-flat' " +
                    "onclick='$.updateRoadPoleCollectModal(" + JSON.stringify(row) + ")'>查看标杆</button> ";
            }
        }, {
            data: "roadPoleId",
            render: function (data, type, row) {
                var button = "";
                button += "<button class='btn btn-primary btn-xs btn-flat' onclick='$.getAllInformation(" + JSON.stringify(row) + ")' title='选择标牌'>" +
                    "<i class='glyphicon glyphicon-eye-open'></i></button>";
                return button;
            }
        }],
        dom: "<'row'<'col-md-12'><'#reportToolbar.col-md-12'>r>t<'row'>",
        initComplete: function () {
            // 下拉工具栏按钮的权限
            $("#reportToolbar").empty();
            var strToolBar = "<div style='margin-top: -32px' class='pull-right'><div class='btn-group'>" +
                "<button type='button' class='btn btn-primary btn-sm btn-flat'><i class='fa fa-cog'></i> 操作</button>" +
                "<button type='button' class='btn btn-primary btn-sm btn-flat dropdown-toggle' " +
                "data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>" +
                "<span class='caret'></span><span class='sr-only'>切换下拉</span></button>" +
                "<ul class='dropdown-menu'>" +
                "<li>" +
                "<button href='#' class='btn btn-primary btn-sm btn-flat btn-block' " +
                "onclick='gReportMainDT.ajax.reload(null, false);'><i class='fa fa-refresh'></i> 刷新</button>" +
                "</li>";

            strToolBar += "</ul></div> " +
                "<div class='input-group-sm' style='display:inline-block'>" +
                "<input id='roadName4S' onkeyup='$.getRoad(1);' type='text' class='form-control mysize' placeholder='路名'>" +
                "&nbsp;<select onchange='$.getRoad(2);' class='form-control mysize' id='startRoad4S'>" +
                "<option value=''>起/止</option>" +
                "</select>&nbsp;" +
                "<select class='form-control mysize' id='endRoad4S'>" +
                "<option value=''>止/起</option>" +
                "</select>&nbsp;</div>" +
                "<div class='input-group input-group-sm'>" +
                "<select id='searchSelect' class='form-control mysize'style='margin-top: 18px'>" +
                "<option value=''  selected = 'selected'>全部</option>" +
                "<option value='安全'>安全</option>" +
                "<option value='不安全'  >不安全</option>" +
                "</select>&nbsp;" +
                "<span class='input-group-btn'>" +
                "<button id='reportSearch' class='btn btn-primary btn-flat' type='button' onclick='$(this).searchReportDT()'>" +
                "<i class='fa fa-search'></i></button></span></div></div>";
            $("#reportToolbar").append(strToolBar);

            $.getRoad(1);

        },
        processing: true,
        serverSide: true,
        ordering: false,
        select: false,
        autoFill: true,
        bDestroy: true,
        displayLength: 20,
        lengthMenu: [[5, 10, 15, 20, 50, 100, 150, -1], [5, 10, 15, 20, 50, 100, 150, "All"]],
        language: {
            url: "zh_cn.json"
        },
        fnDrawCallback: function () {// 序号自增回调函数
            var api = this.api();
            var startIndex = api.context[0]._iDisplayStart;
            api.column(0).nodes().each(function (cell, i) {
                cell.innerHTML = startIndex + i + 1;
            });
        }
    });

    $("#roadPoleDTModalLabel").text("标杆选择");
    $("#roadPoleDTModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
    //隐藏故障上报modal
    $("#addfaultModal").hide();

};
//去空格
$.Trim = function (str, is_global) {
    var result;
    result = str.replace(/(^\s+)|(\s+$)/g, "");
    if (is_global.toLowerCase() == "g") {
        result = result.replace(/\s/g, "");
    }
    return result;
};

$.getRoad = function (type) {
    var id = "endRoad4S";
    var url = "../rds_roadSignManageController/getSectionByRoadName";
    var roadName = $("#startRoad4S").find("option:selected").val();
    if (type == 1) {
        url = "../rds_roadSignManageController/getRoadByRoadName";
        roadName = $.Trim($("#roadName4S").val(), "g");
        id = "startRoad4S";
    }
    $.ajax({
        url: url,
        type: "POST",
        async: false,
        data: {
            "roadName": roadName,
            "actorId": gActorId,
            "orgId": gUserLoginResult.orgId
        },
        success: function (msg) {
            if (msg != null && typeof(msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var roadNames = msg.jsonData;
                    $("#" + id).empty();
                    if (roadNames.length != 0) {
                        orgDataFlag = 0;
                        $("#" + id).append("<option value=''>起/止</option>");
                        for (var i = 0; i < roadNames.length; i++)
                            $("#" + id).append("<option value='" + roadNames[i] + "'>" +
                                roadNames[i] + "</option>");
                    }
                    if (type == 1) {
                        $.getRoad(2);
                    }
                } else {
                    $.alert("获取监管单位数据失败", 2);
                }
            }
        }
    })
};
$("#startRoad4S").change(function () {
    $.getRoad(0);
});

$('#roadPoleSizeUpdate').click(function () {
    $("#roadPoleSizeListUpdate").css("width", $('#roadPoleSizeUpdate').width() + 56);
    $("#roadPoleSizeListUpdate").show();
    $("#roadPoleSizeListUpdate li").hover(function () {
        $("#roadPoleSizeListUpdate li").css("background", "#ffffff").css("color", "#1d1d1d");
        $(this).css("background", "#1674d0").css("color", "#FEFEFE");
        $("#roadPoleSizeUpdate").val($(this).text());
    });
}).blur(function () {
    $("#roadPoleSizeListUpdate").hide();
});

$('#roadPoleSizeAdd').click(function () {
    $("#roadPoleSizeListAdd").css("width", $('#roadPoleSizeAdd').width() + 56);
    $("#roadPoleSizeListAdd").show();
    $("#roadPoleSizeListAdd li").hover(function () {
        $("#roadPoleSizeListAdd li").css("background", "#ffffff").css("color", "#1d1d1d");
        $(this).css("background", "#1674d0").css("color", "#FEFEFE");
        $("#roadPoleSizeAdd").val($(this).text());
    });
}).blur(function () {
    $("#roadPoleSizeListAdd").hide();
});

$.closeRoadPoleDTModal = function () {
    $("#roadPoleDTModal").hide();
    $("#addfaultModal").show();
};
// report搜索框查询操作
$.fn.searchReportDT = function () {
    startRoad4S = $("#startRoad4S").val();
    endRoad4S = $("#endRoad4S").val();
    roadName4S = $("#roadName4S").val();
    gReportMainDT.search($("#searchSelect").val()).draw();
};

//标杆datatable的地图
var X, Y;
$.showMap = function (x, y) {
    X = x;
    Y = y;
    $("#information").show();
    var url = "management/poleMap.html";
    url += "?x=" + x + "&y=" + y + "";//通过这种方式传参数
    $("#reportMyMap").attr("src", url);
    $("#modal-report-map").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
};
//地图的完成按钮
$("#subBtn").click(function () {
    $.clearModal($('#form-report-map'), $('#modal-report-map'));
    $("#coordinateAdd").val(sessionStorage.getItem("x") + "," + sessionStorage.getItem("y"));
    $("#coordinate").val(sessionStorage.getItem("x") + "," + sessionStorage.getItem("y"));
});

//标杆详情
$.updateRoadPoleCollectModal = function (jsonData) {
    switchPic = 0;
    $.getMainOrgNameAndId("mainOrgIdUpdate");
    $("#roadPoleIdUpdate").val(jsonData.roadPoleId);
    $("#provinceUpdate").val(jsonData.province);
    $("#cityUpdate").val(jsonData.city);
    var pid = jsonData.roadPoleRegionId.toString();
    //$.getRegion("areaUpdate", pid.substring(0, 4) + "00");
    $("#areaUpdate").val(jsonData.area);
    $("#orgIdUpdate").val(jsonData.orgName);
    $("#createUserNameUpdate").val(jsonData.userName);
    $("#reCoordinate").val(jsonData.longitude + "," + jsonData.latitude);
    $("#roadNameUpdate").val(jsonData.roadName);
    $("#startRoadUpdate").val(jsonData.startRoad);
    $("#endRoadUpdate").val(jsonData.endRoad);
    if (orgDataFlag == 0)
        $("#mainOrgIdUpdate").val(jsonData.mainOrgId);
    else
        $("#mainOrgIdUpdate").val(gUserLoginResult.orgId);
    $("#roadPolePicUpdate").attr("src", jsonData.roadPolePic);
    $("#roadPoleSecurityUpdate").val(jsonData.roadPoleSecurity);
    $("#roadPoleBridgeUpdate").val(jsonData.roadPoleBridge);
    $("#roadPoleShapeUpdate").val(jsonData.roadPoleShape);
    $("#roadPoleSizeUpdate").val(jsonData.roadPoleSize);
    $("#updateRoadPoleCollectLabel").text("标杆信息");
    $("#updateRoadPoleCollectModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};
//获取主管单位名字
$.getMainOrgNameAndId = function (id) {
    $.ajax({
        url: "../rds_org/getMainOrgNameAndId",
        type: 'post',
        async: false,
        dataType: 'json',
        data: {
            'orgId': gUserLoginResult.orgId
        },
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var orgData = msg.jsonData;
                    $("#" + id).empty();
                    if (orgData.length != 0) {
                        orgDataFlag = 0;
                        for (var i = 0; i < orgData.length; i++)
                            $("#" + id).append("<option value='" + orgData[i].orgId + "'>" +
                                orgData[i].orgName + "</option>");
                    }
                    else {
                        orgDataFlag = 1;
                        $("#" + id).append("<option value='" + gUserLoginResult.orgId + "'>" +
                            gUserLoginResult.orgName + "</option>");
                    }
                } else {
                    $.alert("获取监管单位数据失败", 2);
                }
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function () {
            $.alert("系统错误", 2);
        }
    });
};
//标杆详情的地图
$("#reMyBtnUpdate").click(function () {
    var coordinate = $("#reCoordinate").val().split(",");
    $("#information").hide();
    var url = "management/roadPoleMap.html";
    url += "?x=" + coordinate[0] + "&y=" + coordinate[1] + "&z=1";//通过这种方式传参数
    $("#reportMyMap").attr("src", url);
    $("#modal-report-map").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
});

//选择标牌的地图Modal
$.selectSignMap = function () {
    $("#addfaultModal").modal("hide");
    $("#signSelectMap").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
    $(".modal-backdrop").attr("style", "z-index:-1");
    $(".paginate_button").attr("style", "z-index:0");

    setTimeout(function () {
        $.init_Map();
    }, 200);

};
$.init_Map = function () {
    function initMap() {
        createMap();//创建地图
        setMapEvent();//设置地图事件
        addMapControl();//向地图添加控件
    }

    $.getCoordinate = function () {
        var acId;
        if (gActorId == 1) {
            acId = 1;
        } else {
            acId = 0;
        }
        $.ajax({
            url: "../rds_RoadSignMap/getRoadPoleCoordinate4Map",
            type: 'post',
            async: false,
            dataType: 'json',
            data: {
                "orgId": gUserLoginResult.orgId,
                "orgType": gUserLoginResult.orgType,
                "actorId": acId
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        mData = msg.jsonData;
                    }
                }
            }
        });
    };

    //创建地图函数：
    function createMap() {
        //$("#dituContent").css("height", midHeight);
        map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
        map.centerAndZoom(gPoint, 13);//设定地图的中心点和坐标并将地图显示在地图容器中
        $.getCoordinate();
        $.drawPiont();
    }

    $.drawPiont = function () {
        if (document.createElement('canvas').getContext) {  // 判断当前浏览器是否支持绘制海量点
            var points = [];  // 添加海量点数据
            for (var i = 0; i < mData.length; i++) {
                points.push(new BMap.Point(mData[i].longitude, mData[i].latitude));
            }
            var options = {
                size: 6,
                shape: 1,
                color: '#d3140d'
            };
            pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection
            map.addOverlay(pointCollection);  // 添加Overlay
        } else {
            alert('请在chrome、safari、IE8+以上浏览器查看本示例');
        }
    };

    //地图事件设置函数：
    function setMapEvent() {
        map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.disableDoubleClickZoom();//禁用鼠标双击放大
        map.enableKeyboard();//启用键盘上下左右键移动地图
    }

    //地图控件添加函数：
    function addMapControl() {
        //向地图中添加缩放控件
        var ctrl_nav = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE});
        map.addControl(ctrl_nav);

        //向地图中添加比例尺控件
        var ctrl_sca = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, enableGeolocation: true});
        map.addControl(ctrl_sca);

        var geolocationControl = new BMap.GeolocationControl();
        geolocationControl.addEventListener("locationSuccess", function (e) {

        });
        geolocationControl.addEventListener("locationError", function (e) {
            // 定位失败事件
            alert(e.message);
        });
        map.addControl(geolocationControl);


    }

    function G(id) {
        return document.getElementById(id);
    }

    initMap();//创建和初始化地图

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "suggestId"
            , "location": map
        });
    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

//搜索
    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        setPlace();
    });

    $("#search-button").click(function () {
        myValue = $("#suggestId").val();
        setPlace();
    });

    $("#suggestId").keydown(function (event) {
        if (event.keyCode == 13) {
            myValue = $("#suggestId").val();
            setPlace();
        }
    });

    function setPlace() {
        // map.clearOverlays();   //清除地图上所有覆盖物
        //$.drawPiont();
        function myFun() {
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 15);
            //  map.addOverlay(new BMap.Marker(pp));    //添加标注
        }

        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }

    pointCollection.addEventListener('mouseover', function (e) {
        var info = "";
        var x = formatXY(e.point.lng);
        var y = formatXY(e.point.lat);


        $.ajax({
            url: "../rds_RoadSignMap/getRoadPoleByXY",
            type: 'post',
            // async: false,
            dataType: 'json',
            data: {
                "longitude": x,
                "latitude": y
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess) {
                        var jsonData = msg.jsonData[0];
                        info = '<div style="text-align:center"><img style="height: 200px" src=' + jsonData.roadPolePic + '>' +
                            '<p>地址：' + jsonData.province + ' ' + jsonData.city + ' ' + jsonData.area + '</p>' +
                            '<p>' + jsonData.roadName + ' ' + jsonData.startRoad + '起 ' + jsonData.endRoad + '止</p>' +
                            '<button style="float: right" onclick="$.showAllInformation(' + x + ',' + y + ')">' +
                            '<i class="glyphicon glyphicon-option-horizontal"></i></button>' +
                            '</div>';
                        var opt = {
                            width: 200
                        };
                        var infoWindow = new BMap.InfoWindow(info, opt);  // 创建信息窗口对象
                        map.openInfoWindow(infoWindow, e.point); //开启信息窗口
                    } else {
                        $.alert("信息获取失败", 2);
                    }
                } else {
                    $.alert("信息获取失败", 2);
                }
            }
        });

    });

    function formatXY(n) {
        var number = n + "",
            point = number.indexOf("."),
            len = number.length, len2 = len - point - 1;
        for (; len2 < 6; len2++) {
            number += "0";
        }
        return number;
    }

};
$.closeSignSelectMap = function () {
    $("#signSelectMap").modal("hide");
    $("#addfaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};
$.showAllInformation = function (x, y) {
    $.ajax({
        url: "../rds_RoadSignMap/getRoadPoleByXY",
        type: 'post',
        async: false,
        dataType: 'json',
        data: {
            "longitude": x,
            "latitude": y
        },
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                var jsonData = msg.jsonData[0];
                $.getAllInformation(jsonData);
            }
        }
    })
};

//标牌总体查看
$.getAllInformation = function (jsonData) {
    $("#myDiv").empty();
    $("#address").html(jsonData.province + " " + jsonData.city + " " + jsonData.area + " " + jsonData.roadName + " " + jsonData.startRoad + "起 " + jsonData.endRoad + "止");
    var temp;
    if (jsonData.roadPoleShape == 0)
        temp = "单直杆";
    if (jsonData.roadPoleShape == 1)
        temp = "双直杆";
    if (jsonData.roadPoleShape == 2)
        temp = "单挑杆";
    if (jsonData.roadPoleShape == 3)
        temp = "双挑杆";
    if (jsonData.roadPoleShape == 4)
        temp = "二F杆";
    if (jsonData.roadPoleShape == 5)
        temp = "三F杆";
    if (jsonData.roadPoleShape == 6)
        temp = "门架";
    $("#shape").html(temp);
    if (jsonData.roadPoleSecurity == 0)
        temp = "安全";
    if (jsonData.roadPoleSecurity == 1)
        temp = "不安全";
    $("#security").html(temp);
    if (jsonData.roadPoleBridge == 0)
        temp = "否";
    if (jsonData.roadPoleBridge == 1)
        temp = "是";
    $("#bridge").html(temp);

    $("#create").html(jsonData.userName);
    $("#size").html(jsonData.roadPoleSize);
    $("#company").html(jsonData.orgName);
    $("#mainOrg").html(jsonData.mainOrgName);


    $.ajax({
        url: "../rds_roadSignManageController/getRoadSignCollect",
        type: 'post',
        async: false,
        dataType: 'json',
        data: {
            'roadPoleId': jsonData.roadPoleId
        },
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var Data = msg.jsonData;
                    for (var i = 0; i < Data.length; i++) {
                        var data = Data[i];
                        var roadSignLight;
                        var roadSignShape;
                        var roadSignInstallType;
                        var roadSignMaterial;
                        var roadSignDirection;
                        var roadSignType;
                        var roadSignBug;
                        var roadSignSize = data.roadSignSize;
                        var environment = "日常使用";
                        if (data.environment == 1)
                            environment = "施工配合";
                        var roadSignFixed = "扎带";
                        if (data.roadSignFixed == 1)
                            roadSignFixed = "抱箍";
                        var roadSignSecurity = "安全";
                        if (data.roadSignSecurity != 0) {
                            roadSignSecurity = "不安全";
                        }

                        switch (data.roadSignInstallType) {
                            case 0:
                                roadSignInstallType = "单标志";
                                break;
                            case 1:
                                roadSignInstallType = "合杆";
                                break;
                            case 2:
                                roadSignInstallType = "借杆";
                                break;
                        }
                        switch (data.roadSignLight) {
                            case 0:
                                roadSignLight = "反光";
                                break;
                            case 1:
                                roadSignLight = "发光";
                                break;
                            case 2:
                                roadSignLight = "照明";
                                break;
                        }
                        switch (data.roadSignMaterial) {
                            case 0:
                                roadSignMaterial = "铝板";
                                break;
                            case 1:
                                roadSignMaterial = "塑料板";
                                break;
                            case 2:
                                roadSignMaterial = "其他";
                                break;

                        }
                        switch (data.roadSignShape) {
                            case 0: {
                                roadSignShape = "圆形";
                                break;
                            }
                            case 1: {
                                roadSignShape = "八角形";
                                break;
                            }
                            case 2: {
                                roadSignShape = "正三角";
                                break;
                            }
                            case 3: {
                                roadSignShape = "倒三角";
                                break;
                            }
                            case 4: {
                                roadSignShape = "矩形";
                                break;
                            }
                            case 5: {
                                roadSignShape = "方形";
                                break;
                            }
                        }
                        switch (data.roadSignDirection) {
                            case 0:
                                roadSignDirection = "东";
                                break;
                            case 1:
                                roadSignDirection = "南";
                                break;
                            case 2:
                                roadSignDirection = "西";
                                break;
                            case 3:
                                roadSignDirection = "北";
                                break;
                        }
                        switch (data.roadSignType) {
                            case 0:
                                roadSignType = "警告标志";
                                break;
                            case 1:
                                roadSignType = "禁令标志";
                                break;
                            case 2:
                                roadSignType = "指示标志";
                                break;
                            case 3:
                                roadSignType = "指路标志";
                                break;
                            case 4:
                                roadSignType = "旅游标志";
                                break;
                            case 5:
                                roadSignType = "辅助标志";
                                break;
                            case 6:
                                roadSignType = "作业标志";
                                break;
                            case 7:
                                roadSignType = "告示标志";
                                break;
                        }
                        switch (data.roadSignBug) {
                            case 0:
                                roadSignBug = "正常";
                                break;
                            case 1:
                                roadSignBug = "膜脱落";
                                break;
                            case 2:
                                roadSignBug = "膜淡化";
                                break;
                            case 3:
                                roadSignBug = "逆反射系数不达标";
                                break;
                            case 4:
                                roadSignBug = "卷边";
                                break;
                            case 5:
                                roadSignBug = "转向";
                                break;
                            case 6:
                                roadSignBug = "非国际";
                                break;
                            case 7:
                                roadSignBug = "抱箍缺少";
                                break;
                            case 8:
                                roadSignBug = "净空高不达标";
                                break;
                            case 9:
                                roadSignBug = "设置不合理";
                                break;
                            case 10:
                                roadSignBug = "缺失";
                                break;
                            case 11:
                                roadSignBug = "建议增设";
                                break;
                            case 12:
                                roadSignBug = "与交通组织矛盾";
                                break;
                            case 13:
                                roadSignBug = "内容有误";
                                break;
                            case 14:
                                roadSignBug = "标牌与标杆不配套";
                                break;
                            case 15:
                                roadSignBug = "非公指示牌";
                                break;
                        }
                        var n = i + 1;
                        var html = "<table class=\"table table-bordered table-striped\">\n" +
                            "                        <tr>\n" +
                            "                            <th><b>标牌" + n + "</b><th>";
                        if (data.roadSignIsComplete == 0) {
                            html += "                            <th><button type='button' class='btn btn-danger btn-xs btn-flat' >" +
                                "未审核</button><th>";
                        } else {
                            if (data.reportState == 1)
                                html += "                            <th><button type='button' class='btn btn-default btn-xs btn-flat'>故障申报中</button>";
                            else if (data.reportState == 2)
                                html += "                            <th><button type='button' onclick='$.showReason(" + JSON.stringify(data) + ")' class='btn btn-danger btn-xs btn-flat'>申报失败点击查看原因</button>";
                            else if (data.reportState == 3)
                                html += "                            <th><button type='button' class='btn btn-default btn-xs btn-flat'>故障处理中</button>";
                            else
                                html += "                            <th><button type='button' class='btn btn-default btn-xs btn-flat' " +
                                    "onclick='$.sureRoadSign(" + data.roadSignId + "," + data.roadSignBug + ")' title='申报故障'>" +
                                    "<i class='fa fa-plus-square'></i> 申报</button>";
                        }
                        html += "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td  rowspan=\"8\" colspan=\"3\"><img  onclick=\"$.showPicModal('" + data.roadSignPic + "')\" style=\"width: 230px;height:270px;cursor:pointer\" src=\"" + data.roadSignPic + "\"></td>\n" +
                            "                            <td><b>标志分类：</b></td>\n" +
                            "                            <td>" + roadSignType + "</td>\n" +
                            "                            <td><b>标志含义:</b></td>\n" +
                            "                            <td>" + roadSignType.substring(0, 1) + "" + data.roadSignMeaning + "</td>\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>存在问题:</b></td>\n" +
                            "                            <td>" + roadSignBug + "</td>\n" +
                            "                            <td><b>安全状况:</b></td>\n" +
                            "                            <td>" + roadSignSecurity + "</td>\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>标志形状:</b></td>\n" +
                            "                            <td>" + roadSignShape + "</td>\n" +
                            "                            <td><b>标牌尺寸:</b></td>\n" +
                            "                            <td>" + roadSignSize + "</td>\n" +
                            "\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>标志材料:</b></td>\n" +
                            "                            <td>" + roadSignMaterial + "</td>\n" +
                            "                            <td><b>采集人 :</b></td>\n" +
                            "                            <td>" + data.userName + "</td>\n" +
                            "\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>光源显示:</b></td>\n" +
                            "                            <td>" + roadSignLight + "</td>\n" +
                            "                            <td><b>安装方式:</b></td>\n" +
                            "                            <td>" + roadSignInstallType + "</td>\n" +
                            "\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>固定方式:</b></td>\n" +
                            "                            <td>" + roadSignFixed + "</td>\n" +
                            "                            <td><b>安装日期:</b></td>\n" +
                            "                            <td>" + data.roadSignInstallTime + "</td>\n" +
                            "\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>安装公司:</b></td>\n" +
                            "                            <td>" + data.installOrg + "</td>\n" +
                            "                            <td><b>使用场景:</b></td>\n" +
                            "                            <td>" + environment + "</td>\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>保修期 :</b></td>\n" +
                            "                            <td>" + data.defectsLiabilityPeriod + "年</td>\n" +
                            "                            <td><b>使用年限:</b></td>\n" +
                            "                            <td>" + data.serviceLife + "年</td>\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                            <td><b>标志朝向:</b></td>\n" +
                            "                            <td>" + roadSignDirection + "</td>\n" +
                            "                            <td><b>备注说明:</b></td>\n" +
                            "                            <td colspan=\"7\">" + data.roadSignRemark + "</td>\n" +
                            "                        </tr>\n" +
                            "                        <tr>\n" +
                            "                        </table>";
                        $("#myDiv").append(html);
                    }
                } else {
                    $.alert("数据操作失败", 2);
                }
            } else {
                $.alert('系统错误，请联系管理员', 2);
            }
        }
    });

    $("#img").attr("src", jsonData.roadPolePic);
    $("#img").click(function () {
        $.showPicModal($(this).attr("src"));
    });
    $("#modal-AllInformation").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

var Jdata;
//展示申报失败原因
$.showReason = function (jsonData) {
    Jdata = jsonData;
    $.ajax({
        url: "../rds_fault/getCheckBackBySignFaultId",
        type: "post",
        async: false,
        data: {
            "roadSignId": jsonData.roadSignId
        },
        success: function (msg) {
            if (msg != null && typeof(msg) != "undefined") {
                if (msg.isSuccess == true) {
                    $("#reason").val(msg.jsonData);
                }
                else
                    $.alert("系统错误，请联系管理员", 2);
            }
        }

    });
    $("#showReason_roadSignId").val(jsonData.roadSignId);
    $("#showReasonModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });

};

//确定故障上报的标牌.
$.sureRoadSign = function (roadSignId, roadSignBug) {
    $("#addfault_roadSignId").val(roadSignId);
    $("#addfault_signFaultType").val(roadSignBug);
    console.log(roadSignBug);
    $.ajax({
        url: "../rds_roadSignManageController/getRoadSignByRoadSignId",
        type: "post",
        dataType: "json",
        data: {
            roadSignId: roadSignId
        },
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    data = msg.jsonData;
                    $("#addfault_roadName").text(data.roadName);
                    $("#addfault_address").text(data.province + "" + data.city + "" + data.area + " " + data.roadName + " " + data.startRoad + "(起)--" + data.endRoad + "(止)");
                    $("#addfault_signFaultPic").attr("src", data.roadSignPic);
                    $("#addfault_orgId").val(data.orgId);
                    $("#addfault_mainOrgId").val(data.mainOrgId);
                } else {
                    $.alert("系统错误", 2);
                }
            } else {
                $.alert('系统错误，请联系管理员', 2);
            }
        },
        error: function () {
            $.alert("系统错误！", 4);
        }
    });

    $("#modal-AllInformation").modal("hide");
    $("#roadPoleDTModal").modal("hide");
    $("#showReasonModal").modal("hide");
    $("#signSelectMap").modal("hide");//隐藏地图
    $("#addfaultModal").show();
    $("#addfaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};
//故障上报的验证
$.reportFault = function () {
    if ($("#addfault_address").text() == "" && $("#addfault_roadName").text() == "") {
        $.alert("请选择标牌", 2);
    } else if ($("#addfault_signFaultReason").val() == "") {
        $.alert("请填写故障原因", 2);
    } else if ($("#addfault_signFaultReason").val().length > 200) {
        $.alert("故障原因字数不能超过200", 2);
    } else {
        $("#reportBtn").attr("disabled", true);
        $.ajax({
            url: "../rds_fault/reportSignFault",
            type: "post",
            dataType: "json",
            data: {
                "roadSignId": $("#addfault_roadSignId").val(),
                "signFaultPeopleId": gUserLoginResult.userId,
                "signFaultLevel": $("#addfault_signFaultLevel").val(),
                "signFaultType": $("#addfault_signFaultType").val(),
                "signFaultPic": $("#addfault_signFaultPic").attr("src"),
                "signFaultReason": $("#addfault_signFaultReason").val(),
                "repairAmount": $("#addfault_repairAmount").val(),
                "orgId": $("#addfault_orgId").val(),
                "mainOrgId": $("#addfault_mainOrgId").val()
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        $("#addfaultModal").modal("hide");
                        $.alert("申报成功，等待内部审核", 1);
                        gMainDT.ajax.reload(null, false);
                        $("#addfault_signFaultLevel").val(1);
                        $("#addfault_signFaultType").val(0);
                        $("#addfault_signFaultPic").attr("src", "../images/default_photo.png");
                        $("#addfault_roadName").html("");
                        $("#addfault_address").html("");
                        $("#addfault_repairAmount").val("");
                        $("#addfault_signFaultReason").val("");

                        $("#addfault_roadSignId").val("");
                        $("#addfault_orgId").val("");
                        $("#addfault_mainOrgId").val("");
                    } else {
                        $.alert("系统错误", 2);
                    }
                } else {
                    $.alert('系统错误，请联系管理员', 2);
                }
            },
            error: function () {
                $("#reportBtn").attr("disabled", false);
                $.alert("系统错误！", 4);
            }
        });
    }
};


// 关闭添加故障modal
$.closeAddfaultModal = function () {
    $("#addfault_signFaultLevel").val(1);
    $("#addfault_signFaultType").val(0);
    $("#addfault_signFaultPic").attr("src", "../images/default_photo.png");
    $("#addfault_roadName").html("");
    $("#addfault_address").html("");
    $("#addfault_repairAmount").val("");
    $("#addfault_signFaultReason").val("");

    $("#addfault_roadSignId").val("");
    $("#addfault_orgId").val("");
    $("#addfault_mainOrgId").val("");
    $("#addfault_signFaultId").val("");

    $("#addfault_repairAmount").attr("disabled", false);
    $("#addfault_signFaultType").attr("disabled", false);
    $("#addfault_signFaultLevel").attr("disabled", false);
    $("#addfault_signFaultReason").attr("disabled", false);
    $("#addfault_signBtn").show();
    $("#addfault_signMapBtn").show();
    $("#addfault_signFaultPic").attr("onclick", "$.openUpPic()");
    $("#reportBtn").show();
    $("#updateBtn").hide();

    $("#addfaultModal").modal("hide");
};

//删除故障
$.deleteFaultReport = function (FaultReportIds) {
    var deleteStatus = 0;//判断是否可以删除 0可以删
    var count = 1;
    if (FaultReportIds == 0) {
        var count = $("input:checkbox[id^='checkbox']:checked").length;
        if (count == 0) {
            $.alert("请选择要删除的数据", 2);
            return;
        } else {
            FaultReportIds = "";
            $("input:checkbox[id^='checkbox']:checked").each(function () {
                FaultReportIds += $(this).val() + ",";
                var companyCheck = $(this).attr("data-status");
                if (companyCheck != 0 && companyCheck != -1) {
                    deleteStatus = 1;
                }
            });
            FaultReportIds = FaultReportIds.substring(0, FaultReportIds.length - 1);
        }
    }
    if (deleteStatus == 1) {
        $.alert("故障已上报，无法删除", 2);
    } else {
        bootbox.confirm({
            buttons: {
                confirm: {
                    label: '<i class="fa fa-check"></i> 确定',
                    className: 'btn btn-primary btn-flat'
                },
                cancel: {
                    label: '<i class="fa fa-close"></i> 取消',
                    className: 'btn btn-warning btn-flat pull-left'
                }
            },
            message: '<i class="fa fa-question-circle-o"></i> <b class="customer-title">确定删除该' + count + '条数据吗?</b>',
            callback: function (result) {
                if (result) {
                    $.ajax({
                        url: '../rds_fault/deleteFaultReportByIds',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            "FaultReportIds": FaultReportIds
                        },
                        success: function (msg) {
                            if (msg != null && typeof (msg) != "undefined") {
                                if (msg.isSuccess == true) {
                                    if (msg.jsonData > 0) {
                                        $.alert("数据删除成功", 1);
                                        gMainDT.ajax.reload(null, false);
                                    } else {
                                        $.alert("数据删除失败", 2);
                                    }
                                } else {
                                    $.alert("数据删除失败", 2);
                                }
                            } else {
                                $.alert('系统错误，请联系管理员', 2);
                            }
                        },
                        error: function (msg) {
                            $.alert('系统错误，请联系管理员', 2);
                        }
                    });
                }
            }
        });
    }
};

//datatable标牌详情
$.signDetails = function (data) {
    $("#signProvince").val(data.province);
    $("#signCity").val(data.city);
    $("#signArea").val(data.area);
    $("#coordinate").val(data.longitude + "," + data.latitude);
    $("#signRoadName").val(data.roadName);
    $("#signStartRoad").val(data.startRoad);
    $("#signEndRoad").val(data.endRoad);
    if (data.roadSignPic != "" && data.roadSignPic != null) {
        $("#signRoadSignPic").attr("src", data.roadSignPic);
    }
    else {
        $("#signRoadSignPic").attr("src", "../images/default_photo.png");
    }
    $.ajax({
        url: "../rds_fault/getSignInfoBySignId",
        type: 'post',
        async: false,
        data: {
            userDevice: 'web',
            roadSignId: data.roadSignId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    $("#signCreateUserName").val(msg.jsonData.userName);
                    $("#signOrgName").val(msg.jsonData.orgName);
                    $("#signMainOrgName").val(msg.jsonData.mainOrgName);
                    $("#signEnvironment").val(msg.jsonData.environment);
                    $("#SignRoadSignType").val(msg.jsonData.roadSignType);
                    $("#signRoadSignInstallType").val(msg.jsonData.roadSignInstallType);
                    $("#signRoadSignShape").val(msg.jsonData.roadSignShape);

                    $("#roadSignInfoModalLabel").text("标牌信息");
                    $("#roadSignInfoModal").modal({
                        backdrop: 'static',
                        keyboard: false,
                        show: true
                    });
                } else
                    $.alert("修改失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};

//datatable标牌详细上的地图
$.myBtnMap = function () {
    var coordinate = $("#coordinate").val().split(",");
    var url = "fault/roadPoleAuditMap.html";
    url += "?x=" + coordinate[0] + "&y=" + coordinate[1] + "&z=1";//通过这种方式传参数
    $("#myMap").attr("src", url);
    $("#modal-map").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
};

//审核窗口
var ggactor = 0;
$.showCheckModal = function (jsonData, actor) {
    signMainOrgId = jsonData.mainOrgId;
    signOrgId = jsonData.orgId;
    ggactor = actor;
    MaintenancePeopleNames = "";
    if (gActorId == actor || gActorId == 1) {
        $.ajax({
            url: "../rds_fault/getlongLatitude4Map",
            type: "POST",
            dataType: "json",
            data: {
                "roadSignId": jsonData.roadSignId
            },
            success: function (jsonData) {
                var url = "fault/map.html";
                url += "?x=" + jsonData[0].longitude + "&y=" + jsonData[0].latitude + "";//通过这种方式传参数
                $("#showEventContent4Audit").attr("src", url);
            }
        });
        $("#ac-button").show();
        $("#notac-button").show();
        $("#signFaultId").val(jsonData.signFaultId);
        $("#signFaultCheckBack4Audit").removeAttr("readOnly");
        $("#signFaultId4Audit").html(jsonData.signFaultId);
        $("#signFaultLevel4Audit").html($.getSignFaultLevelCN(jsonData.signFaultLevel));
        $("#signFaultType4Audit").html(faultType[jsonData.signFaultType].name);
        $("#checkPerson4Audit").html(jsonData.mainCheckName);
        $("#signFaultPeopleName4Audit").html(jsonData.signFaultPeopleName);
        $("#signFaultTime4Audit").html(jsonData.signFaultTime);
        $("#repairAmount4Audit").html(jsonData.repairAmount);
        $("#signFaultReason4Audit").html(jsonData.signFaultReason);
        $("#signFaultDescription4Audit").html(jsonData.signFaultDescription);
        $("#signFaultPic4Audit").attr('src', jsonData.signFaultPic);
        $("#preViewImg").attr('src', jsonData.signFaultPic);
        if (gActorId == 3)
            $("#auditModalLabel").text("企业负责人审核");
        if (gActorId == 1)
            $("#auditModalLabel").text("管理员审核");
        $("#auditModal").modal({
            backdrop: 'static',
            keyboard: false,
            show: true
        });

    } else {
        $.alert("无权限", 2)
    }
};
//审核窗口的故障等级
$.getSignFaultLevelCN = function (signFaultLevel) {
    var str = "";
    switch (signFaultLevel) {
        case 1:
            str = "一级";
            break;
        case 2:
            str = "二级";
            break;
        case 3:
            str = "三级";
            break;
        case 4:
            str = "四级";
            break;
        case 5:
            str = "五级";
            break;
    }
    return str;
};
//点击通过按钮
$("#ac-button").click(function () {
        if (signOrgId == signMainOrgId) {
            $.alert("没有选择监管单位", 2);
        } else
            $.signFaultAudit(1, ggactor);
    }
);


//点击直接通过按钮
$("#straight-button").click(function () {
        $("#straight-button").attr("disabled", true);
        $("#ac-button").attr("disabled", true);
        $("#notac-button").attr("disabled", true);
        $.signFaultAudit(2, ggactor);
    }
);

//点击不通过按钮
$("#notac-button").click(function () {
    $.signFaultAudit(-1, ggactor);
});


//审核操作
$.signFaultAudit = function (ispass, actor) {
    var signFaultCheckBack = "";
    signFaultCheckBack = $("#signFaultCheckBack4Audit").val();
    if (signFaultCheckBack == "" && ispass == -1) {
        $.alert('请填写故障反馈', 2);
    } else {
        $.ajax({
            url: "../rds_fault/signFaultAudit2Report",
            type: 'post',
            data: {
                userDevice: 'web',
                isPass: ispass,
                signFaultCheckBack: signFaultCheckBack,
                signFaultId: $("#signFaultId").val(),
                actorId: actor,
                signCheckTime: $.getTime(),
                signFaultPeopleId: gUserLoginResult.userId,
                maintenancePeopleId: null
            },
            dataType: 'json',
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        $.alert("审核成功", 1);
                        $.closeShowModal();
                        //MaintenancePeopleId = null;
                        gMainDT.ajax.reload(null, false);
                    } else
                        $.alert("修改失败！", 2);
                } else {
                    $.alert('系统错误', 2);
                }


            },
            error: function (data) {
                $.alert("系统错误", 2);
            }
        })
    }
};
//关闭审核模态框
$.closeShowModal = function () {
    $("#signFaultCheckBack4Audit").val("");
    $("#auditModal").modal("hide");
};

$("#addfault_signFaultPic").click(function () {
    if (!isAdd)
        $.showPicModal($(this).attr("src"));
});

$("#roadPolePicUpdate").click(function () {
    $.showPicModal($(this).attr("src"));
});

$("#signRoadSignPic").click(function () {
    $.showPicModal($(this).attr("src"))
});

//图片预览
$.showMePhoto = function () {
    if ($("#preViewImg").attr("src") != "") {
        $("#auditModal").modal("hide");
        $("#preModal").modal({
            backdrop: 'static',
            keyboard: false,
            show: true
        });
    } else {
        $.alert("未上传故障图片", 3);
    }
};
// 关闭图片预览
$.closePhoto = function () {
    $("#preModal").modal("hide");
    $("#auditModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

// 打开上传modal框
$.openUpPic = function () {
    $("#upPictureModal").modal({
        backdrop: 'static',
        keyboard: true,
        show: true
    });
};

// 关闭上传modal框
$.closeUpPhModal = function () {
    $("#upPictureModal").modal("hide");
    $("#ossfile").empty();
    clearOssData();
};

//获取图片信息
$.doneUpPhoto = function () {
    var fileInfo = getOssFileInfo();
    fileUrl = fileInfo[0].fileUrl;
    $("#addfault_signFaultPic").attr("src", fileUrl);
    $.closeUpPhModal();
};

//判断文件类型(在需要的js文件添加，文件名务必保持一致)
function judgeFileType(suffix) {
    //图片文件
    if (!(suffix == ".jpg" || suffix == ".JPG" || suffix == ".png" || suffix == ".PNG" ||
            suffix == ".jpeg" || suffix == ".JPEG" || suffix == ".gif" || suffix == ".GIF" ||
            suffix == ".bmp" || suffix == ".BMP")) {
        alert("请选择图片文件！");
        return false;
    }
}

//限制金额输入为0.00
function onlyNumber(obj) {

    //得到第一个字符是否为负号
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d\.]/g, '');
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, '');
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, '.');
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
    //只能输入两位小数
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
    //如果第一位是负号，则允许添加
    if (t == '-') {


    }

}